package cn.iocoder.yudao.module.trade.dal.mysql.followmerchant;


import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
import cn.iocoder.yudao.module.trade.dal.dataobject.followmerchant.SystemFollowMerchant;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Objects;

@Mapper
public interface FollowMerchantMapper extends BaseMapperX<SystemFollowMerchant> {
    default int isFollowMerchant(SystemFollowMerchant followMerchant){
        Long userId = WebFrameworkUtils.getLoginUserId();
        if(userId == null){
            return 0;
        }
        followMerchant.setUserId(userId);
        return insert(followMerchant);
    }

    default int deleteFollowMerchant(@Param("merchantIds") List<Long> merchantIds){
        Long userId = WebFrameworkUtils.getLoginUserId();
        if(userId == null || Objects.isNull(merchantIds)){
            return 0;
        }

        return delete(new LambdaQueryWrapperX<SystemFollowMerchant>()
                .eq(SystemFollowMerchant::getUserId, userId)
                .inIfPresent(SystemFollowMerchant::getMerchantId, merchantIds));
    }
}
